<template>
  <div class="el-header">
    <div class="header-content">
      <div class="header">
        <div class="header-left">
          <!-- 折叠按钮 -->
          <div class="collapse-btn" @click="collapseChage">
            <el-icon v-if="!collapse"><fold /></el-icon>
            <el-icon v-else><expand /></el-icon>
          </div>
          <div class="logo">EVA-CMS管理系统</div>
        </div>
        <div class="header-right">
          <div class="header-user-con">
            <!-- 消息中心 -->
            <div class="btn-bell">
              <el-tooltip
                effect="dark"
                :content="message ? `有${message}条未读消息` : `消息中心`"
                placement="bottom"
              >
                <router-link to="/table">
                  <el-icon class="el-dropdown-link"><bell /></el-icon>
                </router-link>
              </el-tooltip>
              <span class="btn-bell-badge" v-if="message"></span>
            </div>
            <!-- 用户头像 -->
            <div class="user-avator">
              <img src="../assets/image/imgIcon.jpg" alt="" />
            </div>
            <!-- 用户名下拉菜单 -->
            <el-dropdown
              class="user-name"
              trigger="click"
              @command="handleCommand"
            >
              <span class="el-dropdown-link">
                {{ username || "测试用户名" }}
                <el-icon><caret-bottom /></el-icon>
              </span>
              <template #dropdown>
                <el-dropdown-menu>
                  <!-- <el-dropdown-item command="user">个人中心</el-dropdown-item> -->
                  <el-dropdown-item divided command="loginout"
                    >退出登录</el-dropdown-item
                  >
                </el-dropdown-menu>
              </template>
            </el-dropdown>
            <!-- 设置 -->
            <el-icon class="navbar-icon ml-10" @click="showSetting"
              ><Setting
            /></el-icon>
          </div>
        </div>
      </div>
      <system-setting v-model="showDraw"></system-setting>
    </div>
  </div>
</template>
<script lang="ts" setup>
import { Fold, Expand, Bell, CaretBottom } from "@element-plus/icons-vue";
import { computed, onMounted, ref } from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
import SystemSetting from "@/components/Setting.vue";

// 显示设置页面
const showDraw = ref<boolean>(false);
const showSetting = () => (showDraw.value = !showDraw.value);

const message = 2;
const store = useStore();
const username = store.state.userInfo.name;
// const username = localStorage.getItem("ms_username");
const collapse = computed(() => store.state.collapse);
// 侧边栏折叠
const collapseChage = () => {
  store.commit("handleCollapse", !collapse.value);
};

onMounted(() => {
  if (document.body.clientWidth < 1000) {
    collapseChage();
  }
});

// 用户名下拉菜单选择事件
const router = useRouter();

const handleCommand = (command: any) => {
  if (command == "loginout") {
    localStorage.removeItem("ms_username");
    router.push("/login");
  } else if (command == "user") {
    router.push("/user");
  }
};
</script>
<style scoped>
.header {
  position: relative;
  box-sizing: border-box;
  width: 100%;
  height: 70px;
  font-size: 22px;
  /* color: #fff;
  background-color: #242f42; */
}
.collapse-btn {
  float: left;
  padding: 0 21px;
  cursor: pointer;
  line-height: 70px;
}
.header .logo {
  float: left;
  width: 250px;
  line-height: 70px;
}
.header-right {
  float: right;
  padding-right: 50px;
}
.header-user-con {
  display: flex;
  height: 70px;
  align-items: center;
}
.btn-fullscreen {
  transform: rotate(45deg);
  margin-right: 5px;
  font-size: 24px;
}
.btn-bell,
.btn-fullscreen {
  position: relative;
  width: 30px;
  height: 30px;
  text-align: center;
  border-radius: 15px;
  cursor: pointer;
}
.btn-bell-badge {
  position: absolute;
  right: 0;
  top: -2px;
  width: 8px;
  height: 8px;
  border-radius: 4px;
  background: #f56c6c;
  /* color: #fff; */
}
/* .btn-bell .el-icon-bell {
  color: #fff;
} */
.user-name {
  margin-left: 10px;
}
.user-avator {
  margin-left: 20px;
}
.user-avator img {
  display: block;
  width: 40px;
  height: 40px;
  border-radius: 50%;
}
/* .el-dropdown-link {
  color: #000;
  cursor: pointer;
} */
.el-dropdown-menu__item {
  text-align: center;
}
</style>
